#include <iostream>

#include "ros/ros.h"
#include "demo/User.h"

int main(int argc, char* argv[]) {
    std::string nodeName = "Publisher";
    ros::init(argc, argv, nodeName);
    ros::NodeHandle nodeHandle;
    std::string topicName = "demo3";
    uint32_t queueSize = 1000;
    const ros::Publisher &publisher = nodeHandle.advertise<demo::User>(topicName, queueSize); // 创建订阅者，指定消息类型
    demo::User msg; // 创建自定义消息
    msg.name = "publisher";
    msg.age = 30;
    ros::Rate rate(1);
    uint32_t messageId = 0;
    while (ros::ok() == true) {
        publisher.publish(msg); // 发布自定义消息
        rate.sleep();
        ROS_INFO("Publish topic message %d", messageId);
        ++messageId;
    }

    return EXIT_SUCCESS;
}
